<template>
	<!-- pages/recruitment/recruitment.wxml -->
	<view class="recruitment">
		<image class="recruitment_bg"
			src="https://www.hunanlongyun.com/attachment/images/market/10/595/cars/cars2bb54c28f3ad4e5cabbfeef405fdb2b7.png">
		</image>
		<view class="main">
			<image class="recruitment_txt" mode="widthFix"
				src="https://www.hunanlongyun.com/attachment/images/market/10/595/cars/carse486703db28e10fe03811125855aef9d.png">
			</image>
			<view class="recruitment_form">
				<view class="form_container">
					<image class="form_head" src="/static/pages/image/head_info.png"></image>
					<input class="form_input" v-model="real_name" placeholder="输入您的姓名"
						placeholder-style="color: #999999;">
					<input class="form_input" v-model="phone" placeholder="输入您的手机号码"
						placeholder-style="color: #999999;">
					<button class="form_buttom" @tap="onSubmit">提交申请</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// pages/recruitment/recruitment.js
	var app = getApp();

	export default {
		data() {
			return {
				real_name: null,
				phone: null,
				is_shop: null
			};
		},

		components: {},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {},

		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			this.getIsShop();
		},

		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},

		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},

		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},

		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {},

		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {},
		methods: {
			// 是否开店
			getIsShop() {
				app.globalData.util.request({
					url: "entry/wxapp/Api",
					data: {
						m: "monai_market",
						r: "shop.index.is_shop",
						uid: app.globalData.getuid()
					},
					success: res => {
						this.setData({
							is_shop: res.data.data
						});
					}
				});
			},

			showToast(title) {
				wx.showToast({
					title: title,
					duration: 2000,
					icon: 'none'
				});
			},

			onSubmit() {
				if (this.is_shop == 0) return this.showToast('等待后台审核');
				if (!this.real_name) return this.showToast('请选择地址');
				if (!this.phone) return this.showToast('请输入详细地址');
				wx.showLoading({
					title: '加载中'
				});
				app.globalData.util.request({
					url: "entry/wxapp/Api",
					data: {
						m: "monai_market",
						r: "shop.index.add",
						real_name: this.real_name,
						phone: this.phone,
						uid: wx.getStorageSync('uid')
					},
					success: res => {
						this.showToast('提交成功，等待后台审核');
						setTimeout(() => {
							wx.navigateBack();
						}, 1000);
						wx.hideLoading();
					},
					fail: res => {
						wx.hideLoading();
					}
				});
			}

		}
	};
</script>
<style>
	@import "./recruitment.css";
</style>
